/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Vue;


import Modele.ButtonColumn;
import Controller.RecordAction;
import Controller.RemoveAction;
import Modele.Contact;
import Modele.TableModel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableRowSorter;

/**
 *Assemble a Menu and the List of Contact
 * @author Bakalian
 */
public class SeeList {
    private ArrayList<Contact> ContactToShow;
    private JPanel ListBackground;
    private int tri;
    private ContentPane myPanel;
    
    public SeeList(ArrayList<Contact> ContactToShow,int tri) {
        this.ContactToShow = ContactToShow;
        this.tri=tri;
        if(tri ==0) this.myPanel=new ContentPane(new Menu().getMenuBackground(),list());
       
    }
    
    public JPanel list(){
        ListBackground=new JPanel();
        JPanel bouton=new JPanel();
        
     /*   for(int i=0;i<this.ContactToShow.size();i++){
            String ToShow=" FirstName: " +this.ContactToShow.get(i).getFirstName() + " LastName: " +this.ContactToShow.get(i).getLastName()
                    + "HomeAddress: " + this.ContactToShow.get(i).getHomeAddress() + "CompanyAddress: " + this.ContactToShow.get(i).getCompanyAddress() 
                    + "PersonalPhone: " + this.ContactToShow.get(i).getPersonalPhone()+" ProfessionalPhone: " + this.ContactToShow.get(i).getProfessionalPhone()
                    + "HomePage: " + this.ContactToShow.get(i).getHomeAddress()+"Email: "+this.ContactToShow.get(i).getEmail()
                    +" Age: " +this.ContactToShow.get(i).getAge() +"Photo: " +this.ContactToShow.get(i).getPhoto() ;
                    
          //  Object[][] data=
            ListBackground.add(new JLabel(ToShow));
            
        }*/
      //  Object [][] data= new Object[this.ContactToShow.size()][11];
       // Boutton_1 mybouttonR=new Boutton_1();
       
        /*String[] columnNames = {"First Name",
                        "Last Name",
                        "Home Address",
                        "Company Address",
                        "Personal Phone",
        "Professional Phone",
        "Home Site Address",
        "Email",
        "Photo addresse",
        "Age","Supprimer"
                };

        for(int i=0;i<this.ContactToShow.size();i++){
            
                     
                         data[i][0]=this.ContactToShow.get(i).getFirstName();
                         data[i][1]=this.ContactToShow.get(i).getLastName();
                         data[i][2]=this.ContactToShow.get(i).getHomeAddress();
                         data[i][3]=this.ContactToShow.get(i).getCompanyAddress();
                         data[i][4]=this.ContactToShow.get(i).getPersonalPhone();
                         data[i][5]=this.ContactToShow.get(i).getProfessionalPhone();
                         data[i][6]=this.ContactToShow.get(i).getHomeAddress();
                         data[i][7]=this.ContactToShow.get(i).getEmail();
                         data[i][8]=this.ContactToShow.get(i).getPhoto();
                         data[i][9]=this.ContactToShow.get(i).getAge();
                         
                    
                         
                         
                        
        }
        DefaultTableModel model = new DefaultTableModel(data, columnNames);*/
        TableModel model=new TableModel(ContactToShow);// Table Model whic contains our data
        
       
        JTable table = new JTable(model);
        //Class used for Sorting our Table
        TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>((TableModel) table.getModel()); 
        sorter.setSortsOnUpdates(true);
        
        table.setRowSorter(sorter);
        ButtonColumn buttonRenderer = new ButtonColumn();
        table.getColumnModel().getColumn(6).setCellRenderer(buttonRenderer);
        table.getColumnModel().getColumn(7).setCellRenderer(buttonRenderer);
       
        // need this class in order to occupy the whole Panel
        JScrollPane scrollPane=new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      
        scrollPane.setAutoscrolls(true);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        table.setAutoscrolls(true);
        table.setShowGrid(true);
        table.setGridColor(Color.gray);
        
        
      //  table.setTableHeader(new JTableHeader(table.get));
        ListBackground.setLayout(new BorderLayout());
        ListBackground.add(scrollPane,BorderLayout.CENTER);
        bouton.add(new JButton(new RecordAction(table,ContactToShow)));
        bouton.add(new JButton(new RemoveAction(table,ContactToShow)));
        ListBackground.add(bouton,BorderLayout.SOUTH);
        
        return ListBackground;
    }
    
   
    
}
